package com.example.psychologicalappointmentsystem.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 允许来自特定域的跨域请求
        registry.addMapping("/api/**")   // API 路径
                .allowedOrigins("http://localhost:8081")   // 允许的前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")   // 允许的 HTTP 方法
                .allowedHeaders("*")   // 允许的请求头
                .allowCredentials(true);  // 是否允许带上凭证
    }
}
